package com.leetcode.No0777;

import org.junit.Test;

/**
 * @program: leetcode
 * @description: 在LR字符串中交换相邻字符
 * @author: wangzhihua
 * @date: 2022-10-13
 */
public class Solution {
	public boolean canTransform(String start, String end) {
		int len = start.length();
		boolean ans = true;
		for (int i = 0; i < len; ++i) {
			if (start.charAt(i) == end.charAt(i)) {
				continue;
			}
			if (i < len - 1
					&& ((start.charAt(i) == 'X' && end.charAt(i) == 'L') || (start.charAt(i) == 'R' && end.charAt(i) == 'X'))
					&& start.charAt(i) == end.charAt(i + 1) && start.charAt(i + 1) == end.charAt(i)) {
				++i;
				continue;
			}
			if (i == len - 1 && start.charAt(i) == end.charAt(i)) {
				continue;
			}
			ans = false;
			break;
		}
		if (len == 1) {
			ans = (start.charAt(0) == end.charAt(0));
		}
		return ans;
	}

	@Test
	public void test1() {
		String start = "RXXLRXRXL";
		String end = "XRLXXRRLX";
//		System.out.println(this.canTransform(start, end));

		start = "RXXLRXRXLX";
		end = "XRLXXRRLXX";
//		System.out.println(this.canTransform(start, end));

		start = "RXXXXXLRXRXLX";
		end = "XRXLXLXXRRLXX";
//		System.out.println(this.canTransform(start, end));

		start = "X";
		end = "L";
//		System.out.println(this.canTransform(start, end));

		start = "XLLR";
		end =   "LXLX";
//		System.out.println(this.canTransform(start, end));

		start = "LXXLXRLXXL";
		end =   "XLLXRXLXLX";
//		System.out.println(this.canTransform(start, end));

		start = "RXXLRXRXL";
		end =   "XRLXXRRLX";
//		System.out.println(this.canTransform(start, end));

		start = "XXXXXLXXXX";
		end =   "LXXXXXXXXX"; 
		System.out.println(this.canTransform(start, end));
	}
}
